package com.relax.reentrantLock;


import com.relax.readWriteLock.ReadWriteLockDemo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    ReentrantLock lock = new ReentrantLock();

    private void methodA() {
        lock.lock();
        System.out.println(Thread.currentThread().getName() + "获取dLock...开始执行方法");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "获取Lock...方法结束");
        lock.unlock();
        System.out.println("------------------------------");
    }

    public static void main(String[] args) {
        ReentrantLockDemo reentrantLockDemo = new ReentrantLockDemo();
        new Thread(()->{reentrantLockDemo.methodA();}).start();

        new Thread(()->{reentrantLockDemo.methodA();}).start();
    }
}
